#ifndef ESTIMATIONSTATEMANAGER_H_INCLUDED
#define ESTIMATIONSTATEMANAGER_H_INCLUDED

#include <iostream>
#include <list>
#include <ctime>

#include "GpsWrapper.h"
#include "RouteTypes.h"
#include "SqLiteDbWrapper.h"
#include "Estimator.h"



using namespace std;

//EstimationStateManager.h - A state machine that acts as the main engine for calculating
//time estimates and sending messages to the TCP handler. As the state machine must run
//asynchronously, the calling VehicleStateManager handles its execution with the Thread
//class from the portable Boost library - http://www.boost.org

class EstimationStateManager{

    private:
    //'Borrowed' members from other objects
    const VehicleStates* routeTrigger;
    float* odometer;
    SqLiteDbWrapper* db;

    //State Machine Members
    VehicleStates currentState;
    list<Path>* pathList;
    list<Path>::iterator it;

    //Estimation Members
    Estimator estimator;
    float* nodeTimeQueue;
    float avgVelocity;
    time_t avgCntr[2];
    float distance[2];
    float timeDifference;
    float transmitTimeDifference;
    float distDifference;
    float linkTravelled;
    //TODO: Pull interval from Config file?
    int avgInterval;
    int transmitInterval;

    //State Machine Methods
    void updateVelocity();
    bool stateChanged();
    void updateTimeQueue();
    void pushNewNode();

    public:
    EstimationStateManager(VehicleStates* trigger, float* odo, SqLiteDbWrapper* connection, list<Path>* paths, int routeID);
    ~EstimationStateManager();

    //Program flow enters here when the object is passed as an argument to the thread handler
    void operator() ();
};

#endif // ESTIMATIONSTATEMANAGER_H_INCLUDED
